import { OlympicGuessTodayItem } from "./OlympicGuessTodayItem";
import { OlympicGuessData } from "../data/OlympicGuessData";
type int = number;
//class OlympicGuessTodayItems
    
    export  class OlympicGuessTodayItems /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            return;
        }

        public updateData(arg1: Array<any>): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < this._items.length) 
            {
                loc2 = this._items[loc1] as OlympicGuessTodayItem;
                loc2.updateData(OlympicGuessData(arg1[loc1]));
                loc2.shrinkQA();
                ++loc1;
            }
            this.updateLayout();
            return;
        }

        public expandGuessTodayItem(arg1: OlympicGuessData): void
        {
            var loc4=null;
            var loc1=-1;
            var loc2=0;
            while (loc2 < this._items.length) 
            {
                if ((loc4 = this._items[loc2] as OlympicGuessTodayItem).myData != arg1) 
                {
                    loc4.shrinkQA();
                }
                else 
                {
                    loc1 = loc2;
                }
                ++loc2;
            }
            if (loc1 < 0 || loc1 >= this._items.length) 
            {
                return;
            }
            var loc3;
            if ((loc3 = this._items[loc1] as OlympicGuessTodayItem).isExpanding) 
            {
                loc3.shrinkQA();
            }
            else 
            {
                loc3.expandQA();
            }
            this.updateLayout();
            return;
        }

        /* internal  */initView(): void
        {
            var loc2=null;
            this._items = [];
            var loc1=0;
            while (loc1 < 16) 
            {
                loc2 = new OlympicGuessTodayItem();
                this.addChild(loc2);
                this._items.push(loc2);
                ++loc1;
            }
            this.updateLayout();
            return;
        }

        /* internal  */updateLayout(): void
        {
            var loc1=null;
            var loc3=0;
            var loc5=null;
            var loc2=(this.TotalWidth - this.getRowItemsTotalWidth(0)) / 7;
            loc3 = (this.TotalWidth - this.getRowItemsTotalWidth(0)) % 7;
            var loc4=0;
            while (loc4 < 8) 
            {
                loc5 = this._items[loc4] as OlympicGuessTodayItem;
                if (loc1 != null) 
                {
                    loc5.x = loc1.x + loc1.width + loc2;
                    loc5.y = 0;
                    if (loc4 <= loc3) 
                    {
                        loc5.x = loc5.x + 1;
                    }
                    loc1 = loc5;
                }
                else 
                {
                    loc5.x = 0;
                    loc5.y = 0;
                    loc1 = loc5;
                }
                ++loc4;
            }
            loc1 = null;
            loc2 = (this.TotalWidth - this.getRowItemsTotalWidth(1)) / 7;
            loc3 = (this.TotalWidth - this.getRowItemsTotalWidth(1)) % 7;
            loc4 = 8;
            while (loc4 < 16) 
            {
                loc5 = this._items[loc4] as OlympicGuessTodayItem;
                if (loc1 != null) 
                {
                    loc5.x = loc1.x + loc1.width + loc2;
                    loc5.y = this.startY;
                    if (loc4 - 8 <= loc3) 
                    {
                        loc5.x = loc5.x + 1;
                    }
                    loc1 = loc5;
                }
                else 
                {
                    loc5.x = 0;
                    loc5.y = this.startY;
                    loc1 = loc5;
                }
                ++loc4;
            }
            return;
        }

        /* internal  */getRowItemsTotalWidth(arg1: int): int
        {
            var loc4=null;
            var loc1=arg1 * 8;
            var loc2=0;
            var loc3=loc1;
            while (loc3 < loc1 + 8) 
            {
                loc4 = this._items[loc3] as OlympicGuessTodayItem;
                loc2 = loc2 + loc4.width;
                ++loc3;
            }
            return loc2;
        }

        /* internal */ /* const */TotalWidth: int=636;

        /* internal */ /* const */startY: int=74;

        /* internal */ /* const */horizenDistance: int=87;

        /* internal */ /* var */_items: Array<any>;
    }
